using System;
using System.Collections.Generic;

namespace CKY.AgentPlatform.Common.Types
{
    /// <summary>
    /// 统一的聊天消息类型
    /// </summary>
    public class ChatMessage
    {
        /// <summary>
        /// 角色名称
        /// </summary>
        public string Role { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 工具调用ID
        /// </summary>
        public string ToolCallId { get; set; }

        /// <summary>
        /// 工具名称
        /// </summary>
        public string ToolName { get; set; }

        /// <summary>
        /// 工具调用结果
        /// </summary>
        public List<ToolCall> ToolCalls { get; set; } = new List<ToolCall>();
    }

    /// <summary>
    /// 统一的工具调用类型
    /// </summary>
    public class ToolCall
    {
        /// <summary>
        /// 工具ID
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 工具类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 函数名称
        /// </summary>
        public string FunctionName { get; set; }

        /// <summary>
        /// 函数参数
        /// </summary>
        public Dictionary<string, object> FunctionArguments { get; set; }

        /// <summary>
        /// 工具名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 工具参数
        /// </summary>
        public Dictionary<string, object> Parameters { get; set; }

        /// <summary>
        /// 执行结果
        /// </summary>
        public object Result { get; set; }
    }

    /// <summary>
    /// 用户友好异常
    /// </summary>
    public class UserFriendlyException : Exception
    {
        public UserFriendlyException(string message) : base(message) { }
        public UserFriendlyException(string message, Exception innerException) : base(message, innerException) { }
    }

    /// <summary>
    /// MCP工具执行输入 - 统一定义
    /// </summary>
    public class McpToolExecutionInput
    {
        /// <summary>
        /// 工具名称
        /// </summary>
        public string ToolName { get; set; }

        /// <summary>
        /// 工具ID
        /// </summary>
        public string ToolId { get; set; }

        /// <summary>
        /// 工具参数
        /// </summary>
        public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>();

        /// <summary>
        /// 会话ID
        /// </summary>
        public string SessionId { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserId { get; set; }

        /// <summary>
        /// 超时时间（秒）
        /// </summary>
        public int TimeoutSeconds { get; set; } = 30;

        /// <summary>
        /// 超时时间（毫秒）
        /// </summary>
        public int Timeout { get; set; } = 30000;

        /// <summary>
        /// 是否异步执行
        /// </summary>
        public bool Async { get; set; } = false;
    }

    /// <summary>
    /// MCP工具执行结果 - 统一定义
    /// </summary>
    public class McpToolExecutionResult
    {
        /// <summary>
        /// 执行结果
        /// </summary>
        public object Result { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }

        /// <summary>
        /// 错误消息
        /// </summary>
        public string ErrorMessage { get; set; }

        /// <summary>
        /// 工具名称
        /// </summary>
        public string ToolName { get; set; }

        /// <summary>
        /// 工具ID
        /// </summary>
        public string ToolId { get; set; }

        /// <summary>
        /// 元数据
        /// </summary>
        public Dictionary<string, object> Metadata { get; set; }
        /// <summary>
        /// 结果数据
        /// </summary>
        public object Data { get; set; }
    }
}